package com.shell.petinformationmanagementsystem.mapper;

import com.shell.petinformationmanagementsystem.entity.Pet;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper//表示该类是一个MyBatis接口文件，保证能被扫描到Spring容器中
public interface PetMapper {
    //查询所有宠物信息
    @Select("select id,pet_name,age,sex,color,type,master_name from pet")
    List<Pet> findAll();

    //根据id查找宠物信息
    @Select("select id,pet_name,age,sex,color,type,master_name from pet where id=#{id}")
    Pet findById(Integer id);

    //添加宠物信息
    @Insert("insert into pet(pet_name,age,sex,color,type,master_name)values(#{petName},#{age},#{sex},#{color},#{type},#{masterName})")
    @Options(useGeneratedKeys = true,keyProperty = "id") //插入以后自动获取id
    Integer add(Pet pet); //返回值表示更新数量

    //根据id以及传进来的pet，更新宠物信息
    @Update("update pet set pet_name=#{petName},age=#{age},sex=#{sex},color=#{color},type=#{type},master_name=#{masterName} where id=#{id}")
    Integer upda(Pet pet);

    //根据宠物名字删除宠物信息
    @Delete("delete from pet where pet_name=#{name}")
    Integer delByName(String name);
}
